package cn.zhage.aimin.base.model;

import cn.zhage.aimin.base.deserializer.BooleanDeserializer;
import cn.zhage.aimin.base.deserializer.MultiFormatDateDeserializer;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import lombok.Data;
import org.dromara.easyes.annotation.IndexField;
import org.dromara.easyes.annotation.IndexId;
import org.dromara.easyes.annotation.IndexName;
import org.dromara.easyes.annotation.rely.Analyzer;
import org.dromara.easyes.annotation.rely.FieldType;
import org.dromara.easyes.annotation.rely.IdType;

import java.io.Serializable;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;

/*
 *
 * @author 渣哥
 */

@Data
@IndexName("drug_index")
public class DrugIndex implements Serializable {

    /**
     * 药品ID，主键，自增
     */
    @IndexId(type = IdType.CUSTOMIZE)
    private Integer drugId;

    /**
     * 药品名称，例如“阿莫西林胶囊”
     */
    @IndexField(fieldType = FieldType.TEXT, analyzer = "ik_max_word",searchAnalyzer = Analyzer.IK_SMART)
    private String name;

    /**
     * 药品通用名，药品的标准学名
     */
    @IndexField(fieldType = FieldType.TEXT, analyzer = "ik_max_word")
    private String genericName;

    /**
     * 分类ID，与 t_drug_categories 表关联
     */
    @IndexField(fieldType = FieldType.INTEGER)
    private Integer categoryId;

    @IndexField(fieldType = FieldType.TEXT, analyzer = "ik_max_word")
    private String categoryName;

    /**
     * 品牌名称，例如“辉瑞”
     */
    @IndexField(fieldType = FieldType.TEXT, analyzer = "ik_max_word")
    private String brand;

    /**
     * 生产厂家，例如“华东制药”
     */
    @IndexField(fieldType = FieldType.TEXT, analyzer = "ik_max_word")
    private String manufacturer;

    /**
     * 药品描述，详细说明药品的用途和特点
     */
    @IndexField(fieldType = FieldType.TEXT, analyzer = "ik_max_word", searchAnalyzer = Analyzer.IK_SMART)
    private String description;

    /**
     * 剂型，例如“片剂”、“胶囊”、“注射液”
     */
    @IndexField(fieldType = FieldType.TEXT)
    private String dosageForm;

    /**
     * 规格，例如“500mg”、“100单位/ml”
     */
    @IndexField(fieldType = FieldType.TEXT)
    private String strength;

    /**
     * 售价，单位为人民币元
     */
    @IndexField(fieldType = FieldType.KEYWORD)
    private BigDecimal price;

    /**
     * 折扣价，可为空
     */
    @IndexField(fieldType = FieldType.KEYWORD)
    private BigDecimal discountPrice;


    /**
     * 是否需要处方，TRUE 表示需要，FALSE 表示不需要
     */
    @IndexField(fieldType = FieldType.BOOLEAN)
    @JsonDeserialize(using = BooleanDeserializer.class)
    private Boolean prescription;


    @IndexField(fieldType = FieldType.TEXT)
    private String shelfLife;


    @IndexField(fieldType = FieldType.TEXT)
    private String barCode;


    /**
     * 储存说明，例如“避光保存”或“冷藏保存”
     */
    @IndexField(fieldType = FieldType.TEXT)
    private String storageInstructions;

    /**
     * 药品创建时间，默认当前时间
     */
    @IndexField(
            fieldType = FieldType.DATE,
            dateFormat = "yyyy-MM-dd'T'HH:mm:ssXXX"
    )
    @JsonDeserialize(using = MultiFormatDateDeserializer.class)
    private Date createAt;


    /**
     * 药品更新时间，自动更新为当前时间
     */
    @IndexField(
            fieldType = FieldType.DATE,
            dateFormat = "yyyy-MM-dd'T'HH:mm:ssXXX"
    )
    @JsonDeserialize(using = MultiFormatDateDeserializer.class)
    private Date updateAt;

    /**
     * 药品状态，“Available”表示上架，“Unavailable”表示下架
     */
    @IndexField(fieldType = FieldType.INTEGER)
    private Integer status;


    @IndexField(fieldType = FieldType.TEXT)
    private String imgUrl;

    @Override
    public String toString() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return "DrugIndex(" +
                "drugId=" + drugId +
                ", name=" + name +
                ", genericName=" + genericName +
                ", categoryId=" + categoryId +
                ", categoryName=" + categoryName +
                ", brand=" + brand +
                ", manufacturer=" + manufacturer +
                ", description=" + description +
                ", dosageForm=" + dosageForm +
                ", strength=" + strength +
                ", price=" + price +
                ", discountPrice=" + discountPrice +
                ", prescription=" + prescription +
                ", shelfLife=" + shelfLife +
                ", barCode=" + barCode +
                ", storageInstructions=" + storageInstructions +
                ", createAt=" + (createAt != null ? sdf.format(createAt) : null) +
                ", updateAt=" + (updateAt != null ? sdf.format(updateAt) : null) +
                ", status=" + status +
                ", imgUrl=" + imgUrl +
                ")";
    }

}